package servlet;

import entity.Work;
import service.WorkService;
import service.UserService;
import service.impl.WorkServiceImpl;
import service.impl.UserServiceImpl;
import util.ScannerUtils;

import java.util.ArrayList;

public class UserWork {
    UserService userService = new UserServiceImpl();
    WorkService workService = new WorkServiceImpl();

    public void userList(String idNumber) throws Exception{
        System.out.println("个人工作任务");
        System.out.println("请选择：");
        System.out.println("1.查看工作备忘");
        System.out.println("2.添加工作备忘");
        String choice = ScannerUtils.scannerUtil();
        if(choice.equals("1")){
            listWork(idNumber);
        }else if(choice.equals("2")){
            addWork(idNumber,null);
        }
    }
    public void listWork(String idNumber) throws Exception{
        ArrayList<Work> list = workService.findWork(idNumber);
        for (int i = 0; i < list.size(); i++){
            System.out.println(list.get(i).getWork());
        }
        UserWork userWork = new UserWork();
        userWork.userList(idNumber);
    }
    public void addWork(String idNumber, String work) throws Exception{
        if (work == null){
            System.out.println("请输入新的工作备忘");
            work = ScannerUtils.scannerUtil();
            workService.insert(idNumber,work);
            UserWork userWork = new UserWork();
            userWork.userList(idNumber);
        }else {
            workService.insert(idNumber,work);
        }
    }
}
